/***************************************************************************
 *   Copyright (C) 2009 by Zheng Yonglei
 *   zhengyonglei@gmail.com   *
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation; either version 2 of the License, or     *
 *   (at your option) any later version.                                   *
 *                                                                         *
 *   This program is distributed in the hope that it will be useful,       *
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
 *   GNU General Public License for more details.                          *
 *                                                                         *
 *   You should have received a copy of the GNU General Public License     *
 *   along with this program; if not, write to the                         *
 *   Free Software Foundation, Inc.,                                       *
 *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
 ***************************************************************************/

#ifndef __WORDMANAGER_H
#define __WORDMANAGER_H

#include <iostream>
#include <iomanip>
#include <vector>
#include <string>
#include <sstream>
#include <map>
#include <queue>
#include <cassert>

#include <QCoreApplication>
#include <QDir>
#include <QString>
#include <QSettings>
#include <QVariant>
#include <QVector>

#include "SQLiteDB.h"
#include "StaticModule.h"
#include "DictManager.h"
#include "Word.h"

using namespace std;

class WordManager
{
protected:
	map<int, Word*> mWordsMap;//map<word id, word pointer>
	QVector<int>mWordsVector;//mWordsVector[index] = word id

	int mCurWordID;
	int mCurWordIndex;
	int mLastWordID;


	set<QString> mWordSet;
	map<QString, QString> mWordTransformation;

public:
	WordManager();
	~WordManager();

	void getBasicInfoByActiveState();
	void getBasicInfoByResumeList();
	virtual void addWord(int id);

	void clearWordContainers();
	virtual void finishCurTask();

	Word* getCurWord();
	Word* getWord(int id);
	Word* getWordByIndex(int index);
	int getWordCount(){return mWordsMap.size();}
	int getCurWordID(){return mCurWordID;}
	void setCurWordId(int id);
	int getCurWordIndex(){return mCurWordIndex;}
	int getCurWordIndexByID(int id){return mWordsVector.indexOf(id);}

	void browseWordByIndex(int index);

	int random(int size);

	void loadWordSet();
	set<QString>& getWordSet(){return mWordSet;}

	void loadWordTransformation();
	map<QString, QString>& getWordTransformation(){return mWordTransformation;}
};

#endif //__WORDMANAGER_H
